/**
 * @author htqw
 * @param {mysql2.Connection} connection 
 * @param {string} table 
 * @param {Object.<string, string>} data 
 * @param {string | undefined} where 
 * @returns 
 */

export default function updateTableCols(connection, table, data, where) {
    return new Promise((resolve, reject) => {
        connection.query(`UPDATE ${table} SET ${Object.entries(data).map(([key, value]) => `${key} = ${value}`).join(', ')}` + 
            ` ${where ? `WHERE ${where}` : ''}`, function (err, result) {
            if (err) 
                reject(err)
            else
                resolve(result)
        })
    })
}